package com.hyh.util;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.support.v4.app.ActivityCompat;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2019/1/27.
 */

public class PermissionUtil {

    public static boolean verifyAppPermissions(Activity activity){
        List<String> permissions = new ArrayList<>();
        int recordAudioPermission = ActivityCompat.checkSelfPermission(activity, Manifest.permission.RECORD_AUDIO);
        if(recordAudioPermission!= PackageManager.PERMISSION_GRANTED){
            permissions.add(Manifest.permission.RECORD_AUDIO);
        }
        int readPhonePermission = ActivityCompat.checkSelfPermission(activity,Manifest.permission.READ_PHONE_STATE);
        if(readPhonePermission!=PackageManager.PERMISSION_GRANTED){
            permissions.add(Manifest.permission.READ_PHONE_STATE);
        }
        int readContactsPermission = ActivityCompat.checkSelfPermission(activity,Manifest.permission.READ_CONTACTS);
        if(readContactsPermission!=PackageManager.PERMISSION_GRANTED){
            permissions.add(Manifest.permission.READ_CONTACTS);
        }
        if(permissions.size()>0){
            String appPermissions[] = new String[permissions.size()];
            for(int i=0;i<permissions.size();i++){
                appPermissions[i] = permissions.get(i);
            }
            ActivityCompat.requestPermissions(activity,appPermissions,0);
            return false;
        }else{
            return true;
        }
    }
}
